<?php


namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class PdfMenuSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        if (!DB::table('admin_menu')->where('title', '模块管理')->exists()) {
            DB::table('admin_menu')->insert([
                'parent_id' => 0,
                'order' => DB::table('admin_menu')->max('order') + 1,
                'title' => '模块管理',
                'icon' => 'fa-folder-open',
                'extension' => '',
                'show' => 1,
                'created_at' => now(),
                'updated_at' => now(),
            ]);
        }

        $admin_menu = DB::table('admin_menu')->where('title', '模块管理')->first();

        if (!DB::table('admin_menu')->where('title', '教材点读')->exists()) {
            DB::table('admin_menu')->insert([
                'parent_id' => $admin_menu->id,
                'order' => DB::table('admin_menu')->max('order') + 1,
                'title' => '教材点读',
                'uri' => '/',
                'extension' => '',
                'show' => 1,
                'created_at' => now(),
                'updated_at' => now(),
            ]);
        }
        $admin_menu = DB::table('admin_menu')->where('title', '教材点读')->first();

        if (!DB::table('admin_menu')->where('title', '点读图片')->exists()) {
            DB::table('admin_menu')->insert([
                'parent_id' => $admin_menu->id,
                'order' => DB::table('admin_menu')->max('order') + 1,
                'title' => '点读图片',
                'uri' => '/pdfImage',
                'extension' => '',
                'show' => 1,
                'created_at' => now(),
                'updated_at' => now(),
            ]);
        } else {
            DB::table('admin_menu')->where('title', '点读图片')->update([
                'parent_id' => $admin_menu->id,
            ]);
        }

        $this->command->info('教材点读菜单路由填充完成！');
    }
}
